package com.test.delay.handler;

import com.rabbitmq.client.Channel;
import com.test.delay.config.RabbitConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.time.LocalDateTime;

@Component
public class delayHandler {
    private static final Logger log = LoggerFactory.getLogger(delayHandler.class);

    @RabbitListener(queues = {RabbitConfig.REGISTER_QUEUE_NAME})
    public void listenerDelayQueue(String delay, Message message, Channel channel){
        log.info("[listenerDelayQueue 监听的消息] - [消费时间] - [{}] - [{}]", LocalDateTime.now(), delay);
        try{
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        }catch(IOException e){
            //todo 容错处理
            e.printStackTrace();
        }
    }
}
